package com.example.backend.dto;

import lombok.Data;

import java.time.Instant;
import java.util.List;
import java.util.Map;

/**
 * 统计报表DTO
 */
@Data
public class StatisticsReportDto {
    
    // 实时统计仪表盘
    private DashboardStats dashboardStats;
    
    // 团队绩效报表
    private TeamPerformanceReport teamPerformance;
    
    // SLA达成率统计
    private SLAStatisticsReport slaStatistics;
    
    // 工单趋势图表
    private TrendChartData trendCharts;
    
    /**
     * 仪表盘统计数据
     */
    @Data
    public static class DashboardStats {
        private Long totalTickets;
        private Long openTickets;
        private Long inProgressTickets;
        private Long resolvedTickets;
        private Long closedTickets;
        private Long todayTickets;
        private Long weekTickets;
        private Long monthTickets;
        private Long overdueTickets;
        private Double avgResolutionTimeHours;
        private Double avgSatisfactionScore;
        private Map<String, Long> priorityDistribution;
        private Map<String, Long> statusDistribution;
        private Map<String, Long> sourceDistribution;
        private List<TopPerformer> topPerformers;
        private List<RecentActivity> recentActivities;
    }
    
    /**
     * 团队绩效报表
     */
    @Data
    public static class TeamPerformanceReport {
        private List<TeamMemberPerformance> teamMembers;
        private TeamOverallStats overallStats;
        private List<PerformanceMetric> metrics;
        private List<PerformanceTrend> trends;
    }
    
    /**
     * SLA统计报表
     */
    @Data
    public static class SLAStatisticsReport {
        private Double overallSLAAchievementRate;
        private Double responseSLAAchievementRate;
        private Double resolutionSLAAchievementRate;
        private Map<String, Double> slaByPriority;
        private Map<String, Double> slaByCategory;
        private Map<String, Double> slaByTeam;
        private List<SLAViolation> slaViolations;
        private List<SLAImprovement> slaImprovements;
    }
    
    /**
     * 趋势图表数据
     */
    @Data
    public static class TrendChartData {
        private List<ChartDataPoint> ticketTrend; // 工单数量趋势
        private List<ChartDataPoint> resolutionTrend; // 解决数量趋势
        private List<ChartDataPoint> satisfactionTrend; // 满意度趋势
        private List<ChartDataPoint> slaTrend; // SLA达成率趋势
        private List<ChartDataPoint> priorityTrend; // 优先级分布趋势
        private List<ChartDataPoint> categoryTrend; // 分类分布趋势
    }
    
    /**
     * 顶级表现者
     */
    @Data
    public static class TopPerformer {
        private Long userId;
        private String userName;
        private String userRole;
        private Long ticketsResolved;
        private Double avgResolutionTime;
        private Double avgSatisfactionScore;
        private Double slaAchievementRate;
    }
    
    /**
     * 最近活动
     */
    @Data
    public static class RecentActivity {
        private String activityType;
        private String description;
        private String userName;
        private Instant timestamp;
        private Long ticketId;
        private String ticketNumber;
    }
    
    /**
     * 团队成员绩效
     */
    @Data
    public static class TeamMemberPerformance {
        private Long userId;
        private String userName;
        private String userRole;
        private String department;
        private Long totalTickets;
        private Long resolvedTickets;
        private Long overdueTickets;
        private Double avgResolutionTimeHours;
        private Double avgSatisfactionScore;
        private Double slaAchievementRate;
        private Long totalComments;
        private Long totalAttachments;
        private Map<String, Long> ticketsByStatus;
        private Map<String, Long> ticketsByPriority;
    }
    
    /**
     * 团队整体统计
     */
    @Data
    public static class TeamOverallStats {
        private Long totalTeamMembers;
        private Long activeTeamMembers;
        private Long totalTicketsHandled;
        private Double teamAvgResolutionTimeHours;
        private Double teamAvgSatisfactionScore;
        private Double teamSLAAchievementRate;
        private Long teamTotalComments;
        private Long teamTotalAttachments;
    }
    
    /**
     * 绩效指标
     */
    @Data
    public static class PerformanceMetric {
        private String metricName;
        private String metricDescription;
        private Double currentValue;
        private Double targetValue;
        private Double previousValue;
        private String unit;
        private String trend; // UP, DOWN, STABLE
        private Double changePercentage;
    }
    
    /**
     * 绩效趋势
     */
    @Data
    public static class PerformanceTrend {
        private String metricName;
        private List<ChartDataPoint> dataPoints;
        private String trendDirection;
        private Double trendStrength;
    }
    
    /**
     * SLA违规记录
     */
    @Data
    public static class SLAViolation {
        private Long ticketId;
        private String ticketNumber;
        private String violationType; // RESPONSE, RESOLUTION
        private Instant violationTime;
        private Long violationDurationMinutes;
        private String assignedToName;
        private String priority;
        private String category;
    }
    
    /**
     * SLA改进建议
     */
    @Data
    public static class SLAImprovement {
        private String improvementArea;
        private String suggestion;
        private String priority; // HIGH, MEDIUM, LOW
        private Double expectedImprovement;
        private String implementationEffort;
    }
    
    /**
     * 图表数据点
     */
    @Data
    public static class ChartDataPoint {
        private String label;
        private Double value;
        private Instant timestamp;
        private Map<String, Object> metadata;
    }
}
